package nl.ru.rd.facedetection.nnbfd.neuralnetwork;

import java.util.ArrayList;

/**
 * A Layer of Inputs in a Neural Network. Enables the assignment of input values to a Network.
 * 
 * @author Wouter Geraedts (s0814857)
 */
public class InputLayer implements Layer
{
	private static final long serialVersionUID = -6836250256912998655L;
	private Layer nextLayer;
	private ArrayList<Input> inputs = new ArrayList<Input>();
	private double[] activations;

	/**
	 * Add an Input Node to this Layer.
	 * 
	 * @param input
	 */
	public void addInput(Input input)
	{
		this.inputs.add(input);
	}

	@Override
	public void bind(Layer layer)
	{
		this.nextLayer = layer;
	}

	@Override
	public double getActivation(int neuronI)
	{
		return this.activations[neuronI];
	}

	@Override
	public int getSize()
	{
		return this.inputs.size();
	}

	@Override
	public void update()
	{
		if(this.activations == null || this.activations.length != this.getSize())
			this.activations = new double[this.getSize()];

		for(int i = 0; i < this.getSize(); i++)
			this.activations[i] = this.inputs.get(i).getValue();
	}

	@Override
	public Layer getNextLayer()
	{
		return this.nextLayer;
	}
}
